﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using ETL.Business.Handlers.ProjectHandlers;
using ETL.Business.Helpers;
using ETL.Common;
using ETL.Web.CustomCredential;
using ETL.Web.Filters;
using ETL.Web.Models;
using WebMatrix.WebData;

namespace ETL.Web.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        [Authorize]
        [InitializeSimpleMembership]
        public ActionResult Index()
        {
            // check authenticated
            if (!WebSecurity.IsAuthenticated) return RedirectToAction("Login", "Account");

            // Program Initialize
            (new ProgramInitialize()).Execute(ETLCredential.UserId, ETLCredential.UserFullName);

            #region Check user role for projects loading

            bool isAdminRole = Roles.IsUserInRole(Constants.RoleName.Admin);
            bool isLeadRole = Roles.IsUserInRole(Constants.RoleName.Lead);

            // Set to viewbag
            ViewBag.IsAdminRole = isAdminRole;
            ViewBag.IsLeadRole = isLeadRole;
            if(isAdminRole)
            {
                return RedirectToAction("Index", "ManageActualResource");
            }
            else
            {
                return RedirectToAction("Index", "EnTimeLog");
            }
            
            #endregion
        }

    }
}
